<#import "../macro/components.ftl" as components/>
<#include "../macro/layout_default.ftl"/>

<@head>
<link rel="stylesheet" href="/misc/app/css/product_list.css"/>
<link href="/misc/adminlte-2.3.7/plugins/twitter-bootstrap-v2/docs/assets/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="/misc/adminlte-2.3.7/plugins/daterangepicker/daterangepicker.css"/>
</@head>

<@body>
<script src="/misc/app/js/qrcode_product.js"></script>
<script src="/misc/adminlte-2.3.7/plugins/daterangepicker/moment.min.js"></script>
<script src="/misc/adminlte-2.3.7/plugins/daterangepicker/daterangepicker.js"></script>
<script src="/misc/adminlte-2.3.7/plugins/twitter-bootstrap-v2/docs/assets/js/browser.js"></script>
<script src="/misc/adminlte-2.3.7/plugins/twitter-bootstrap-v2/docs/assets/js/bootstrap-typeahead.js"></script>
<script>


	jQuery('#search_pname,#search_pname1').typeahead({
		source: function (query, process) {
	        var parameter = {'pname': query};
	        $.get('/querypname', parameter, function (data) {
	        	var resultstr = "";
	        	 for(i=0;i<data.length;i++)
				 {
				  	resultstr +=","+data[i].name+"_"+data[i].number+"_"+data[i].id+"_"+data[i].pcount;
				 }
	        	resultstr = resultstr.substring(1);
	        	var result = resultstr.split(",");
	            process(result);
	        });
    	},
		updater: function (item) {
			$("#pid").val(item.split("_")[2]);
			$("#pid1").val(item.split("_")[2]);
			$("#pbccount").val(item.split("_")[3]);
			$("#pbccount1").val(item.split("_")[3]);
			//console.log($("#pid").val());
			item=item.split("_")[0]+"_"+item.split("_")[1];
			return item.replace(/<a(.+?)<\/a>/, ""); //这里一定要return，否则选中不显示
		},
		items: 8, //显示8条
		delay: 500 ,//延迟时间
		minLength: 1
    	
	});

	jQuery('#search_qcname').typeahead({
		source: function (query, process) {
			var type_value = jQuery("#type").val();
			if(type_value!=1 && type_value!=2 && type_value!=3 ){
				return;
			}
	        var parameter = {'qcname': query,type:type_value};
	        jQuery.get('/queryqcname', parameter, function (data) {
	        	var resultstr = "";
	        	 for(i=0;i<data.length;i++)
				 {
				  resultstr +=","+data[i].name+"_"+data[i].id ;
				 }
	        	resultstr = resultstr.substring(1);
	        	var result = resultstr.split(",");
	            process(result);
	        });
    	},
		updater: function (item) {
			return item.replace(/<a(.+?)<\/a>/, ""); //这里一定要return，否则选中不显示
		},
		items: 8, //显示8条
		delay: 500 ,//延迟时间
		minLength: 1
    	
    	
});



</script>
</@body>

<@layout_default>
<div class="box">
    <div class="box-header with-border">
        <span class="pull-right text-muted">共 ${pagelist.resultTotal} 条记录</span>
        <input type="hidden" id="resultTotal_hidden" value=" ${pagelist.resultTotal}" />
        <form class="form-inline" action="/qrcodeproduct">
            <div class="input-group">
                <div class="input-group-addon">产品名称:</div>
                <input type="text" class="form-control" style="width: 260px" name="pname" value="${pname!}" 
                placeholder="商品名称" autocomplete="off"/>
            </div>
             <div class="input-group">
                <div class="input-group-addon">批次号:</div>
                <input type="text" class="form-control" style="width: 260px" name="batch_nub" value="${batch_nub!}" 
                placeholder="批次号" autocomplete="off"/>
            </div>
            <div class="input-group">
                <div class="input-group-addon">二维码批次:</div>
                <input type="text" class="form-control" style="width: 260px" name="qcname" value="${qcname!}" 
                placeholder="二维码批次" autocomplete="off"/>
            </div>
            <br>
             <br>
            <div class="input-group">
                <div class="input-group-addon">状态:</div>
                <select class="form-control" name="sta">
                    <option value="">全部</option>
                    <option value="1"   <#if (sta!  == "1")> selected="selected" </#if> >正常</option>
                    <option value="0"  <#if (sta!  == "0")> selected="selected" </#if> >解绑</option>
                </select>
            </div>
            &nbsp; &nbsp; &nbsp;
            <div class="input-group">
                <div class="input-group-addon">是否营销:</div>
                <select class="form-control" name="is_act">
                    <option value="">全部</option>
                    <option value="1"   <#if (is_act!  == "1")> selected="selected" </#if> >是</option>
                    <option value="0"  <#if (is_act!  == "0")> selected="selected" </#if> >否</option>
                </select>
            </div>
			&nbsp; &nbsp; &nbsp;	
            <button type="submit" class="btn btn-warning"><i class="fa fa-search"></i> 查询</button>&nbsp; &nbsp; &nbsp;
             <button type="button" id="search_reset" class="btn btn-warning"><i class="fa "></i> 重置</button>&nbsp; &nbsp; &nbsp;
            <button type="button" class="btn btn-warning" name="btn_new" data-toggle="modal" data-target="#md_new"><i class="fa fa-plus"></i> 新增绑定</button>
        </form>
        <form class="form-inline hide">
            <input class="form-control"/>
            <input type="email" class="form-control"/>
            <button type="submit" class="btn btn-default">Send invitation</button>
        </form>
    </div>

    <!-- /.box-header -->
    <div class="box-body">
        <table class="table table-striped table-hover">
            <tr>
                <th>ID</th>
                <th>绑定产品</th>
                <th>批次号</th>
                <th>二维码批次</th>
                <th>开始编号</th>
                <th>结束编号</th>
                <th>数量</th>
                <th>类型</th>
                <th>状态</th>
                <th>是否营销</th>
                <th>生成时间</th>
                <th>生产日期</th>
                <th>操作人</th>
                <th>操作</th>
            </tr>
            <#list pagelist.result as item>
                <tr >
                    <td style="vertical-align:middle;">${item.id}</td>
                    <td style="vertical-align:middle;">${item.pname!}<br>(${item.pnumber!})</td>
                   	<td style="vertical-align:middle;">${item.batch_nub!}</td>
                    <td style="vertical-align:middle;">${item.qcname}</td>
                    <td style="vertical-align:middle;">
                    	<#if item.g_s_no!=0>
                    	${item.g_s_no!}<hr>
                    	</#if>
                    	${item.s_no!}
                    	
                    	</td>
                    <td style="vertical-align:middle;">
                    	<#if item.g_e_no!=0>
	                    ${item. g_e_no!}<hr>
	                    </#if>
	                    ${item. e_no!}
                    
                    </td>
                    
                    <td style="vertical-align:middle;">
                    	<#if item.g_q_count!=0>
	                    ${item.g_q_count!}<hr>
	                     </#if>
	                    ${item.q_count!}
                    
                    </td>
                    <td style="vertical-align:middle;">
                    	<#if item.g_q_count==0>
	                    	<#if item.type==1>
	                    	<span class="text-green">瓶码/盒码</span>
	                    	<#elseif item.type==2>
	                    	<span class="text-yellow">箱码</span>
	                    	</#if>
	                    <#else>
	                    	<span class="text-yellow">箱码<#if item.type==3><br>(组合码)</#if></span><hr>
	                    	<span class="text-green">瓶码/盒码<#if item.type==3><br>(组合码)</#if></span>
                    	</#if>	
                    </td>
                    <td style="vertical-align:middle;"><#if item.sta==true><span class="text-green">已绑定</span><#elseif item.sta==false><span class="text-yellow">解绑</span><#else><span class="text-danger">未知</span></#if></td>
                    <td style="vertical-align:middle;">
	                    <#if item.is_act=1>
		                    	<span class="text-green">是</span>
                                <#if isStartMarket == 1>
                                    <button type="button" class="btn btn-default btn-xs" name="btn_is_act"  data-id="${item.id?c}"  data-type="0" data-qrtype="${item.type}" >停用营销</button>
                                </#if>
	                     <#elseif item.is_act==0>
		                    	<span class="text-yellow">否</span>
                                <#if isStartMarket == 1>
		                   	        <button type="button" class="btn btn-default btn-xs" name="btn_is_act"  data-id="${item.id?c}"  data-type="1" data-qrtype="${item.type}" >启用营销</button>
                                </#if>
                         <#else>
	                    	    <span class="text-danger">未知</span>
	                    </#if>
                    </td>
                    <td style="vertical-align:middle;">${item.c_time?number_to_datetime}</td>
                    <td style="vertical-align:middle;"><#if item.produce_date == 0 > <#else> ${item.produce_date?number_to_date} </#if> </td>
                    <td style="vertical-align:middle;">${item.c_admin}</td>
                    <td style="vertical-align:middle;">
                    <#if item.sta==true>
                    
                     <button type="button" class="btn btn-default btn-xs" name="btn_edit" data-toggle="modal" data-target="#md_edit" data-id="${item.id?c}"  data-qcname="${item.qcname}" data-type="${item.type}">更换产品</button>
                     
                      <button type="button" class="btn btn-default btn-xs" name="btn_delete_bangdings" data-qrcodeproductid="${item.id?c}" data-type="${item.type}">解绑</button>
                      
                       <button type="button" class="btn btn-default btn-xs" name="btn_new" data-toggle="modal" data-target="#md_new" data-pname="${item.pname}_${item.pid?c}" data-type="${item.type}" data-pcount="${item.pcount}" >追加</button>
                       
                       
                     	<#else>
                     	<span class="text-red">解绑时间：${(item.u_time!0)?number_to_datetime}</span><br>
                     	<span class="text-red">解绑操作人 ：${item.u_admin!"系统"}</span><br>
                     </#if >
                    </td>
                </tr>
            </#list>
        </table>
        <table class="table table-striped table-hover">
        	<tr>
        		<td colspan="13" style="text-align:right;background-color:white;">
        			<a href="javascript:void(0);" name="btn_qrcodeproduct_export"><i class="glyphicon glyphicon-save"></i> 数据导出</a>
        		</td>
        	</tr>
        </table>
    </div>
    <!-- /.box-body -->
    <div class="box-footer text-center">
       <@components.pagination "${pagelist.rquesturl}&page=$page",pagelist.page,pagelist.pageTotal/>
    </div>
</div>


<!--=========== Modals =============-->
<!-- md_new -->
<div class="modal" id="md_new" tabindex="-1">
    <div class="modal-dialog"   role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title"><i class="fa fa-plus"></i> <span id="_title">新增/追加</span></h4>
            </div>
            <div class="modal-body" style="max-height: 637px;">
                <form class="form-horizontal" name="form_new">
                  <div class="form-group">
                  		<input type="hidden"  id="pid" name ="pid"/>
                  		<input type="hidden"  id="pbccount" name ="pbccount"/>
                        <label class="col-sm-2 control-label"><strong class="text-red bold"> *</strong> 绑定产品:</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" placeholder="绑定产品" name="pname"  id="search_pname" data-provide="typeahead" data-items="8" autocomplete="off" />
                        </div>
                    </div>
                     <div class="form-group">
                        <label class="col-sm-2 control-label"><strong class="text-red bold"> *</strong> 批次号:</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" placeholder="批次号" name="batch_nub"  id="_batch_nub"  autocomplete="off" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">生产日期:</label>
                        <div class="col-sm-10">
                           <input type="text" class="form-control" placeholder="生产日期"   id="produce_date" name="produce_date" size="18">
                        </div>
                    </div>
                    
                      <div class="form-group">
                        <label class="col-sm-2 control-label"><strong class="text-red bold"> *</strong> 二维码类型:</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="type" name="type">
                                <option value="1">瓶码/盒码</option>
                                <option value="2">箱码</option>
                                <option value="3">组合码</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"><strong class="text-red bold"> *</strong> 二维码批次:</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" placeholder="二维码批次" name="qcname"  id="search_qcname" data-provide="typeahead" data-items="8" autocomplete="off"/>
                        </div>
                    </div>
                   <div class="form-group">
                        <label class="col-sm-2 control-label"><strong class="text-red bold"> *</strong> 二维码规格:</label>
                        <div class="col-sm-10">
                        	 <input type="text" class="form-control" placeholder="二维码规格" name="pbcId"  id="_pbcid" readonly/>
                        	 <!-- <input type="hidden"  name="pbcId"  id="_pbcidbak"/>-->
                        </div>
                    </div>
                    
                     <div class="form-group">
                        <label class="col-sm-2 control-label"><strong class="text-red bold"> *</strong> 剩余数量(枚):</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="_leftnub"  placeholder="剩余数量" name="nubs" readonly/>
                        </div>
                    </div>
                    
                    <hr>
                    
                     <h4 class="modal-title">编号绑定</h4>
                     <br>
                    
                    <div class="form-group" id="xmsdiv" style="display:none;">
                        <label class="col-sm-2 control-label"><strong class="text-red bold"> *</strong> 箱码开始编号:</label>
                        <div class="col-sm-10">
                        	<input type="hidden"  id="xms_bak" />
                            <input type="text" class="form-control" id="xms"  placeholder="箱码开始编号" name="xms" readonly/>
                        </div>
                    </div>
                    
                       <div class="form-group" id="xmediv"  style="display:none;">
                        <label class="col-sm-2 control-label"><strong class="text-red bold"> *</strong>箱码结束编号:</label>
                        <div class="col-sm-10">
                        	<input type="hidden"  id="xme_bak" />
                            <input type="text" class="form-control" id="xme" placeholder="箱码结束编号" name="xme"  />
                        </div>
                    </div>
                    <div class="form-group" id="xmbdnumdiv"  style="display:none;">
                        <label class="col-sm-2 control-label"><strong class="text-red bold"> *</strong>箱码绑定数量(枚):</label>
                        <div class="col-sm-10">
                        	<input type="hidden"  id="xmbdnum_bak" />
                            <input type="text" class="form-control" id="xmbdnum" placeholder="箱码绑定数量" name="xmbdnum" readonly/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"><strong class="text-red bold"> *</strong>瓶码/盒码开始编号:</label>
                        <div class="col-sm-10">
                       		 <input type="hidden"  id="pms_bak" />
                            <input type="text" class="form-control" id="pms"  placeholder="瓶码/盒码开始编号" name="pms" readonly/>
                        </div>
                    </div>
                    
                       <div class="form-group">
                        <label class="col-sm-2 control-label"><strong class="text-red bold"> *</strong>瓶码/盒码结束编号:</label>
                        <div class="col-sm-10">
                        	<input type="hidden"  id="pme_bak" />
                            <input type="text" class="form-control" id="pme" placeholder="瓶码/盒码结束编号" name="pme"  />
                        </div>
                    </div>
                    
                   	   <div class="form-group" id="bdnumdiv"  style="">
                        <label class="col-sm-2 control-label"><strong class="text-red bold"> *</strong>瓶码/盒码绑定数量(枚):</label>
                        <div class="col-sm-10">
                        	<input type="hidden"  id="bdnum_bak" />
                            <input type="text" class="form-control" id="bdnum" placeholder="瓶码/盒码绑定数量" name="bdnum" readonly/>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="btn_new_save" name="btn_new_save">绑定</button>
            </div>
        </div>
    </div>
</div>

<!--=========== Modals =============-->
<!-- md_edit -->
<div class="modal" id="md_edit" tabindex="-1">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title"><i class="fa fa-plus"></i> 更换产品</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" name="form_edit">
                	<input type="hidden" id="id" name="id">
                	<input type="hidden" id="pid1" name="pid">
                	<input type="hidden" id="_type" name="type">
                	<input type="hidden" id="qrpcount" name="qrpcount">
                	<input type="hidden" id="pbccount1" name="pbccount1">
                	
                  <div class="form-group">
                        <label class="col-sm-2 control-label"><strong class="text-red bold"> *</strong> 绑定产品:</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" placeholder="绑定产品" name="pname"  id="search_pname1" data-provide="typeahead" data-items="8"  autocomplete="off"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"><strong class="text-red bold"> *</strong> 批次号:</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" placeholder="批次号" name="batch_nub"  id="_batch_nub"  autocomplete="off" />
                        </div>
                    </div>
                    <div class="form-group">
		            <label class="col-sm-2 control-label"><strong class="text-red bold"> *</strong> 二维码批次:</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" placeholder="二维码名称" name="qcname"  id="_qcname" data-provide="typeahead" data-items="8" autocomplete="off"/>
                        </div>
                    </div>
                   
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="btn_edit_save" name="btn_edit_save">保存更改</button>
            </div>
        </div>
    </div>
</div>
</@layout_default>